package start.action;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class HelloController {

    @RequestMapping("/")
    public String index() {
        return "Greetings from Spring Boot!";
    }

    /*@RequestMapping("t01")
    public RestResponse t01(){
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
        RestResponse restResponse = new RestResponse();
        //String retJson = HttpClientUtil.sendPost("http://localhost:9017/fssc-eas-web/boe/test", "{}", "123");
        try {
            // 在运行一个job的时候需要添加至少一个参数，这个参数最后会被写到batch_job_execution_params表中，
            // 不添加这个参数的话，job不会运行，并且这个参数在表中中不能重复，若设置的参数已存在表中，则会抛出异常，
            // 所以这里才使用时间戳作为参数
            JobParameters jobParameters = new JobParametersBuilder()
                    .addLong("timestamp", System.currentTimeMillis())
                    .addString("name", "lizemin")
                    .toJobParameters();

            // 获取job并运行
            Job job = dataBatchJob.dataHandleJob();
            JobExecution execution = jobLauncher.run(job, jobParameters);
            System.out.println(execution);

            restResponse.setSuccess(true);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return restResponse;
    }*/

}